home *** CD-ROM | disk | FTP | other *** search
- (*===========================================================================*)
- (* Subroutine to swap message blocks *)
- (* *)
- (* Copyright 1989, 1991 by H. Roy Engehausen. All rights reserved. *)
- (* *)
- (*===========================================================================*)
-
- PROCEDURE msg_resize(VAR msg_ptr : msg_index_ptr; new_subject_size : BYTE);
- VAR
-
- i : BYTE;
- m_overhead : WORD;
- msg_route_look : msg_r_ptr;
- n_msg_ptr : msg_index_ptr;
- w_msg_ptr : msg_index_ptr;
-
- BEGIN;
-
- {$IFDEF POINT_CHK}
- test_pointer(msg_ptr);
- {$ENDIF}
-
- (*-----------------------------------------------------------------------*)
- (* Calculate overhead! *)
- (*-----------------------------------------------------------------------*)
-
- w_msg_ptr := msg_ptr;
- m_overhead := OFS(w_msg_ptr^.msg_i_mb.msg_subj[1]) - OFS(w_msg_ptr^);
-
- (*-----------------------------------------------------------------------*)
- (* Get spot for new message and move things in *)
- (*-----------------------------------------------------------------------*)
-
- GETMEM(n_msg_ptr, m_overhead + new_subject_size);
-
- MOVE(msg_ptr^, n_msg_ptr^, m_overhead);
-
- (*-----------------------------------------------------------------------*)
- (* Fixup forward and backward pointers *)
- (*-----------------------------------------------------------------------*)
-
- w_msg_ptr := n_msg_ptr^.msg_i_next;
- w_msg_ptr^.msg_i_last := n_msg_ptr;
-
- w_msg_ptr := n_msg_ptr^.msg_i_last;
- w_msg_ptr^.msg_i_next := n_msg_ptr;
-
- (*-----------------------------------------------------------------------*)
- (* Fixup start/end pointers *)
- (*-----------------------------------------------------------------------*)
-
- IF msg_index_start = msg_ptr THEN
- msg_index_start := n_msg_ptr;
-
- IF msg_index_end = msg_ptr THEN
- msg_index_end := n_msg_ptr;
-
- (*-----------------------------------------------------------------------*)
- (* Find and fixup forward list chain *)
- (*-----------------------------------------------------------------------*)
-
- w_msg_ptr := msg_index_start;
-
- WHILE (w_msg_ptr <> msg_ptr) AND (w_msg_ptr <> NIL) DO
- BEGIN;
-
- {$IFDEF POINT_CHK}
- test_pointer(w_msg_ptr);
- {$ENDIF}
-
- IF w_msg_ptr^.msg_i_fwd_l = msg_ptr THEN
- BEGIN;
- w_msg_ptr^.msg_i_fwd_l := n_msg_ptr;
- w_msg_ptr := NIL;
- END
- ELSE
- w_msg_ptr := w_msg_ptr^.msg_i_next;
-
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Find and fixup fnr list *)
- (*-----------------------------------------------------------------------*)
-
- w_msg_ptr := msg_index_start;
-
- WHILE (w_msg_ptr <> msg_ptr) AND (w_msg_ptr <> NIL) DO
- BEGIN;
-
- {$IFDEF POINT_CHK}
- test_pointer(w_msg_ptr);
- {$ENDIF}
-
- IF w_msg_ptr^.msg_i_fnm_l = msg_ptr THEN
- BEGIN;
- w_msg_ptr^.msg_i_fnm_l := n_msg_ptr;
- w_msg_ptr := NIL;
- END
- ELSE
- w_msg_ptr := w_msg_ptr^.msg_i_next;
-
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Sleep a while. Allows other pointers to clear *)
- (*-----------------------------------------------------------------------*)
-
- FOR i := 1 TO 20 DO
- task_switch;
-
- (*-----------------------------------------------------------------------*)
- (* Throw away old message *)
- (*-----------------------------------------------------------------------*)
-
- FREEMEM(msg_ptr, m_overhead + LENGTH(msg_ptr^.msg_i_mb.msg_subj));
-
- msg_ptr := n_msg_ptr;
-
- {$IFDEF POINT_CHK}
- test_pointer(msg_ptr);
- {$ENDIF}
-
- {$IFDEF FREE_CHK}
- test_free_list;
- {$ENDIF}
-
- END;